package client

import (
	serverCommon "fiberCommonUtils/common"
	"fmt"
	"github.com/gofiber/fiber/v2"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"mongoDB"
)

// IsBoundIDInfo 是否绑定了身份信息
func (c *Client) IsBoundIDInfo() (string, bool) {
	if len(c.AuthInfo.IDNumber) > 10 {
		return c.AuthInfo.IDNumber, true
	}
	return "", false
}

// LoadClientExamType 客户读取他的考试类型和车辆型号
func LoadClientExamType(c *fiber.Ctx) error {
	_id := c.Locals("ClientID").(primitive.ObjectID)
	_client := &Client{ID: _id}
	ctx, cancel := mongoDB.MongoDBTimeoutContext()
	defer cancel()
	if err := _client.FindByID(ctx); err != nil {
		return fiber.NewError(500, "客户信息读取失败,", err.Error())
	}
	return c.JSON(serverCommon.MakeSuccessJson(fmt.Sprint(
		_client.VehicleModel,
		",",
		_client.ExamType,
	)))
}
